import Vue from 'vue'
import moment from 'moment'

import VueLazyload from 'vue-lazyload'
 
Vue.use(VueLazyload)

// component repo
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'

// richText editor
import VueQuillEditor from 'vue-quill-editor'
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

// markdown
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

import App from './App.vue'
import router from './router'
import store from './store'
import httpRequest from '@/assets/httpRequest.js'
Vue.prototype.$http = httpRequest
Vue.use(Antd)
Vue.use(VueQuillEditor, /* { default global options } */)
Vue.use(mavonEditor)
Vue.config.productionTip = false

Vue.filter('filterPublishTime', (date) => {
  const dateStr = moment(date).format('YYYY-MM-DD')
  const lastThreeDate = moment().subtract(2, 'days').format('YYYY-MM-DD')
  // 如果发布日期为最近三天，就显示相对时间，否则显示具体的日期
  if (moment(dateStr).isBefore(lastThreeDate)) {
    return moment(date).format('YYYY/MM/DD HH:mm:ss')
  } else {
    return moment(date).fromNow()
  }
})

Vue.filter('filterContentType', (val) => {
  return val === 'richText' ? '富文本' : 'Markdown'
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
